const {Solar, SolarUtil, HolidayUtil} = require('lunar-javascript')

//获取指定年的假期数量，参数year:年份，例2022,12
function getHolidaySum(year,month) {
    let HolidaySum = 0; //记录假期数量
    let dayNums = SolarUtil.getDaysOfMonth(year, month); //获取该月天数
    for(let day = 1;day <= dayNums; day++) { //检测天
        let d = HolidayUtil.getHoliday(year, month, day);
        if(d) { //是法定 节假日 或 调休日
            HolidaySum++;
            // console.log(d.getDay() + " " + d.getName() + (d.isWork()?"调休":"放假"));
        } else {
            //判断星期
            d = Solar.fromYmd(year, month, day)
            let week = d.getWeek();
            if(week == 0 || week == 6) {
                HolidaySum++;
                // console.log(d.toYmd() + " 双休");
            }
        }
    }
    return HolidaySum;
}

//获取指定年的假期数量，参数year:年份，例2022
function getWorkdaySum(year,month) {
    let WorkdaySum =  SolarUtil.getDaysOfMonth(year, month) - getHolidaySum(year,month);
    return WorkdaySum;
}

//var startTimeJs = Date.now();
/* 执行输出 */
// 一个当中月休息日
let MonthHolidaySum = getHolidaySum(2022,4);
// 一个月当中的工作日

let MonthWorkdaySum = getWorkdaySum(2022,4);
//var endTimeJs = Date.now();
//console.log("用时: " + (endTimeJs - startTimeJs)/1000 + "s : js");
console.log("该月休息日共: "+MonthHolidaySum);
console.log("该月工作日共: "+MonthWorkdaySum);